<?php
/**
 * 支付方式管理
 * @author Administrator
 */
class payment extends admin{
    public function __construct(){
        parent::__construct();
    }
    
    //提现列表
    public function index(){
       $list=db()->getAll('select * from x_payment');
       $tpl=$this->Template();
       $tpl->assign('list',$list);
       $tpl->display(); 
    }
    
    //添加用户
    public function add(){
        if(IS_AJAX){
             if(!isset($_POST['name'])||empty($_POST['name'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写支付名称'));
             if(!isset($_POST['label'])||empty($_POST['label'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写标签'));
             if(!isset($_POST['params'])||empty($_POST['params'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写参数'));
           /*
             if(!isset($_POST['app_id'])||empty($_POST['app_id'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用id'));
             if(!isset($_POST['key'])||empty($_POST['key'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用key'));
             if(!isset($_POST['url'])||empty($_POST['url'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用接口url'));
             if(!isset($_POST['notify_url'])||empty($_POST['notify_url'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用回调url'));
           */  
             if(isset($_POST['status'])&&$_POST['status']==1) $data['status']=1;
             else $data['status']=0;
             $data['name']=trim($_POST['name']);
             $data['label']=trim($_POST['label']);
             $data['params']=trim($_POST['params']);
           /*
             $data['app_id']=trim($_POST['app_id']);
             $data['key']=trim($_POST['key']);
             $data['url']=trim($_POST['url']);
             $data['notify_url']=trim($_POST['notify_url']); 
           */
             
             
            $insert_id=db()->insert('x_payment',$data);
            if($insert_id) $this->ajaxReturn(array('status'=>'y','info'=>'添加成功'));
            else $this->ajaxReturn(array('status'=>'n','info'=>'添加失败'));
        }else{
            $tpl=$this->Template();
            $tpl->display();
        }
    }
    //编辑用户
    public function edit(){
        if(IS_AJAX){
           if(!isset($_POST['name'])||empty($_POST['name'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写支付名称'));
           if(!isset($_POST['label'])||empty($_POST['label'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写标签'));
         /*  
           if(!isset($_POST['app_id'])||empty($_POST['app_id'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用id'));
           if(!isset($_POST['key'])||empty($_POST['key'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用key'));
           if(!isset($_POST['url'])||empty($_POST['url'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用接口url'));
           if(!isset($_POST['notify_url'])||empty($_POST['notify_url'])) $this->ajaxReturn(array('status'=>'n','info'=>'请填写应用回调url'));
         */  
           if(isset($_POST['status'])&&$_POST['status']==1) $data['status']=1;
           else $data['status']=0;
           $data['name']=trim($_POST['name']);
           $data['label']=trim($_POST['label']);
           $data['params']=trim($_POST['params']);
         /*  
           $data['app_id']=trim($_POST['app_id']);
           $data['key']=trim($_POST['key']);
           $data['url']=trim($_POST['url']);
           $data['notify_url']=trim($_POST['notify_url']);
         */  
           $insert_id=db()->update('x_payment',$data,'id='.$_GET['id']);
           if($insert_id) $this->ajaxReturn(array('status'=>'y','info'=>'修改成功'));
           else $this->ajaxReturn(array('status'=>'n','info'=>'修改失败'));
        }else{
            $id=(int)$_GET['id'];
            $vo=db()->getRow('select * from x_payment where id='.$id);
            $tpl=$this->Template();
            $tpl->assign('vo',$vo);
            $tpl->display();
        }
    }
    //删除用户
    public function delete(){
        if(IS_AJAX){
              $id=(int)$_GET['id'];
              $affert_id=db()->delete('x_payment','id='.$id);
              if($affert_id) $this->ajaxReturn(array('status'=>'y','info'=>'删除成功'));
              else $this->ajaxReturn(array('status'=>'n','info'=>'删除失败'));
        }
    }
    
}